﻿using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Patterns.Tools.CodeGenerators.GoogleCode.Sidebar
{
	public class SidebarModel : WikiModel
	{
		private int _minimumCount;

		private static readonly Regex _underscore = new Regex(@"_+");

		public string Name{ get; set; }
		public IEnumerable<HierarchicalScanResults> Items { get; set; }
		public IEnumerable<ScanResults> OrderedItems { get; private set; }

		public override void Initialize()
		{
			OrderedItems = Items.SelectMany(item => item.Dump()).ToArray();
			_minimumCount = OrderedItems.Select(item => _underscore.Matches(item.Name).Count).Min();
		}

		public string Indent(string item)
		{
			return new string(' ', (_underscore.Matches(item).Count - _minimumCount) * 2);
		}
	}
}